using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

using System.Windows.Forms;

namespace ArgoszLite
{
    public delegate void ArgoszCloseHandler();



    class ArgoszControl
    {
        private List<String> activeService = new List<string>();
        private Settings set;
        
        public event ArgoszCloseHandler CloseEvent;
        
        private void OnCloseEvent()
        {
            CloseEvent();
        }

        public ArgoszControl()
        {
            Settings set = Settings.Instance;
        }

        public void StartCameraCapture()
        {
            if (activeService.Contains("CameraCapture") == false)
            {
                activeService.Add("CameraCapture");

                Thread cameraCaptureThread = new Thread(new ThreadStart(cameraCaptureStart));
                cameraCaptureThread.Start();
            }
        }
        public Boolean StartControlManager()
        {
            Boolean ret = false;

            if (activeService.Contains("Control") == false)
            {
                activeService.Add("Control");
                SettingsManager settManager = new SettingsManager();
                settManager.ShowDialog();
                if (settManager.DialogResult == DialogResult.OK)
                {
                    ret = true;
                }
            }
            return ret;
        }
        public void StartView()
        {
            if (activeService.Contains("CameraCapture") == true && activeService.Contains("View") == false)
            {
                activeService.Add("View");

                Thread cameraCaptureThread = new Thread( new ThreadStart(viewStart));
                cameraCaptureThread.Start();

            }
        }


        private void cameraCaptureStart()
        {
            CameraCapture cameraCapture = new CameraCapture();
            Settings setts = Settings.Instance;
               
            int i;
            for (i = 0; i < setts.Camera_num; i++ )
                cameraCapture.Start(i);

            CloseEvent += new ArgoszCloseHandler(cameraCapture.CloseEventListener);
            cameraCapture.Start_capture();
        }

        private void viewStart()
        {
            View view = new View();
            view.Start();
            OnCloseEvent();
        }
    }
}
